import { ref, watchEffect } from 'vue'
import { defineStore } from 'pinia'
export const discussStore = defineStore('discussStore', () => {
    const userComment: any = ref()//用户发表的评论 整合为一个对象 包括用户基本信息等
    const replyComment: any = ref()//回复...
    interface discuss {
        email: string,
        replyEmail?: string,
        files: string,
        replyFiles?: string,
        nickname: string,
        replyNickname?: string,
        content: string,
        replyCount: number,
        coolCount: number,
        hotCount: number,
        createtime: string,
        count?: number,
        lock: string,
        beloneTo: number,
    }
    const comment = ref<discuss[]>([])
    const repltComment = ref<discuss[]>([])
    watchEffect(() => {
        if (userComment.value === undefined) {
            return
        }
        comment.value.push(userComment.value)
    })
    watchEffect(() => {
        if (replyComment.value === undefined) {
            return
        }
        repltComment.value.push(replyComment.value)
    })
    function initComment(data: any) {
        comment.value.length = 0
        data.forEach((e: any) => {
            comment.value.push(e)
        });
    }
    function initRepltComment(data: any) {
        repltComment.value.length = 0
        data.forEach((e: any) => {
            repltComment.value.push(e)
        });
    }
    return {
        userComment, replyComment, comment, repltComment, initComment, initRepltComment
    }
})